/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.Tags;
import factory.DBConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author theworldiwant
 */
public class MySQLTagsDAO extends TagsDAO{
    
    @Override
    public void addTags(int prodId, String tags) {
       //INSERT INTO `webdeve`.`tags` (`id`, `tags`, `bookId`) VALUES (1, 'fe', 1);
        try {
            // TODO code application logic here
            DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
            Connection conn = myFactory.getConnection();
            PreparedStatement pstmt = conn.prepareStatement("INSERT INTO `webdeve`.`tags` (`id`, `tags`, `bookId`) VALUES (?, ?, ?); ");
            DAOFactory myDAOFactory = DAOFactory.getInstance(DAOFactory.MYSQL);
                pstmt.setInt(1, getCurId()+1);
                pstmt.setString(2, tags);
                pstmt.setInt(3, prodId);
                pstmt.executeUpdate();
              
           
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(MySQLTagsDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void deleteTags(int prodId, String tags) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public LinkedList<Tags> getAllTags(int prodId) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getCurId() {
         int ctr=0;
            DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
            Connection conn = myFactory.getConnection();
            PreparedStatement pstmt2;
        try {
            pstmt2 = conn.prepareStatement("select id from tags");
            ResultSet rs=pstmt2.executeQuery();
            while(rs.next())
                ctr=rs.getInt("id");
        } catch (SQLException ex) {
            Logger.getLogger(MySQLTagsDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
           
            
        return ctr;
    }
 
    
}
